|
|
|
|
|
|
|
Figure 5.16.
Laying out the range-
checking controls
on the text form. |
|
|
|
|
|
|
|
|
After setting these values, add the code in Listing 5.29 to the test form. |
|
|
|
|
|
|
|
|
Listing 5.29. Adding code to handle the InRange properties. |
|
|
|
|
|
|
|
|
Private Sub cmdOK_Click()
If vtxInRange.CheckRange = True Then
vtxInRange.InRangeValidate
End If
End Sub
Private Sub vtxInRange_InRangeError(vValue As Variant)
'
MsgBox "InRange Error Reported!"
'
End Sub |
|
|
|
|
|
|
|
|
Notice the addition of the validation code behind the cmdOK button. This is required, even though you added built-in validation within the control itself. Remember that the Lost_Focus event was used to trigger the InRangeValidate routine. What if the user loads the form, enters data in every field but this one and then proceeds by pressing OK? As you may have guessed, nothing happens since the vtxInRange control never received focus. This is the essence of form-level validation. |
|
|
|
|
|
|
|
|
Save and run the project. You see an error whenever your input range is out of bounds. |
|
|
|
|
|